package com.gpipe.dirwatcherRealtime;

import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.*;

import com.gpipe.dbwriter.Mysql;
import com.gpipe.dbwriter.SendResultData;
import com.gpipe.tools.BaseAreaModel;
import com.gpipe.tools.GpipeInit;

public class InitialMethod {

    public static void main(String[] args) throws SQLException {
        // TODO Auto-generated method stub
        InitialMethod InitialMethod = new InitialMethod();
        StringBuffer flag=new StringBuffer("check");
//        InitialMethod.getBasestationBase(flag);
        System.out.println(flag);
    }

//    private Properties prop = new Properties();

//    public InitialMethod() {
//        InputStream in = Object.class.getResourceAsStream("/com/gpipe/properties/inputData.properties");
//        try {
//            prop.load(in);
//
//
//
//
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//
//    }

    public List getTimePeriod() {
        List list = new ArrayList();


        return list;
    }

    public Map<String, BaseAreaModel> getBaseArea() {
        Map<String, BaseAreaModel> result = new HashMap<String, BaseAreaModel>();
        Mysql mysql = new Mysql();
        Connection conn = mysql.createConnect();
        ResultSet resultSet = mysql.readMysql("select * from base_area_conf_all", conn);
        try {
            while (resultSet.next()) {
                String key = resultSet.getString(ConfOfMysqlModel.confBaseAreaModelParas[6]) + "|" + resultSet.getString(ConfOfMysqlModel.confBaseAreaModelParas[7]);
                BaseAreaModel val = new BaseAreaModel(resultSet.getString(ConfOfMysqlModel.confBaseAreaModelParas[0]), resultSet.getString(ConfOfMysqlModel.confBaseAreaModelParas[1]), resultSet.getString(ConfOfMysqlModel.confBaseAreaModelParas[2]), resultSet.getString(ConfOfMysqlModel.confBaseAreaModelParas[3]), resultSet.getString(ConfOfMysqlModel.confBaseAreaModelParas[4]), resultSet.getString(ConfOfMysqlModel.confBaseAreaModelParas[5]), resultSet.getString(ConfOfMysqlModel.confBaseAreaModelParas[6]), resultSet.getString(ConfOfMysqlModel.confBaseAreaModelParas[7]), resultSet.getString(ConfOfMysqlModel.confBaseAreaModelParas[8]), resultSet.getString(ConfOfMysqlModel.confBaseAreaModelParas[9]), resultSet.getString(ConfOfMysqlModel.confBaseAreaModelParas[10]));
                result.put(key, val);
                //lac|ci:BaseAreaModel
            }
            conn.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return result;
    }

    /*
     * Initialize the configuration file of basestation.
     * key:lac|ci value:area|region_id
     * 
     */
    public Map getBaseRegion() throws SQLException {
        Map result = new HashMap();
        SendResultData mysqlByProperty = new SendResultData();
        Connection connection = mysqlByProperty.createConnect();
        GpipeInit.writeLogs("Initialize the BaseRegion file.");
        Statement stmt = connection.createStatement(); //创建Statement对象
        String sql = "select * from base_conf_gz_zrx_4region";    //要执行的SQL
        ResultSet rs = stmt.executeQuery(sql);//创建数据对象
        while (rs.next()) {
            result.put(rs.getString(1) + "|" + rs.getString(2), rs.getString(3) + "|" + rs.getString(7));
        }
        rs.close();
        stmt.close();
        connection.close();
        return result;
    }

    /*
     * Initialize the configuration file of basestation.
     * key:lac|ci value:longitude|latitude
     */
    public Map getBasestation() throws SQLException {
        String tbN =Conf.baseTBN;
        Map result = new HashMap();
        SendResultData mysqlByProperty = new SendResultData();
        Connection connection = mysqlByProperty.createConnect();
        GpipeInit.writeLogs("Initialize the basestation file.");
        Statement stmt = connection.createStatement(); //创建Statement对象
        String sql = "select * from "+tbN;    //要执行的SQL
        ResultSet rs = stmt.executeQuery(sql);//创建数据对象
        while (rs.next()) {
//                System.out.println(rs.getString(1)+"|"+rs.getString(2)+","+rs.getString(5)+"|"+rs.getString(6));
            result.put(rs.getString(1) + "|" + rs.getString(2), rs.getString(5) + "|" + rs.getString(6) + "|" + rs.getString(3));
        }
        rs.close();
        stmt.close();
        connection.close();
        return result;
    }

    /*
     * Initialize the configuration file of inputdata.
     */
    public Map getInputdataConf() throws SQLException {
        Map result = new HashMap();
        Properties prop = new Properties();
        InputStream in = Object.class.getResourceAsStream("/com/gpipe/properties/inputData.properties");
        try {
            prop.load(in);
        } catch (IOException e) {
            e.printStackTrace();
        }

        Iterator it = prop.entrySet().iterator();
            while (it.hasNext()) {
                Map.Entry<String, String> entry = (Map.Entry<String, String>) it.next();
                String key = entry.getKey();
                String value = entry.getValue();
                result.put(key.trim(), value.trim());
            }
        return result;
    }

}
